$(function () {
useLayDateMultiple("tasktimestart");
useLayDateMultiple("tasktimesend");
  var options = {
    url: api + "/scabpm/bpm/my/todoTaskList",
    listType: 'bpm',
    updateUrl: '/pages/bpm/task/edit',
    method: 'post',
    modalName: "发起申请",
    columns: [
      {
        field: 'subject',
        title: '流程标题',
      },
      {
        field: 'name',
        title: '任务名称'
      },
      {
        field: 'taskType',
        title: '类型',
        align: 'center',
        formatter: function (value, row, index) {
          return typeDict(value)
        }
      },
      {
        field: 'status',
        title: '状态',
        align: 'center',
        formatter: function (value, row, index) {
          return statusDict(value)
        }
      },
      {
        field: 'priority',
        title: '紧急程度',
        align: 'center',
        formatter: function (value, row, index) {
          return custFormat(value)
        }
      },
      {
        field: 'createTime',
        title: '任务创建时间',
      }, {
        title: '操作',
        formatter: function (value, row, index) {
          var actions = [];
          var name = '处理任务【'+row.subject+'】'
          actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="$.operate.editFullBpm(\'' + row.taskId + '\',\'' + name + '\')"><i class="fa fa-edit"></i>办理</a> ');
          actions.push('<a class="btn btn-primary btn-xs" href="javascript:void(0)" onclick="flowImage(\'' + row.instId + '\',\'' + row.defId + '\',\'' + row.taskId + '\')"><i class="fa fa-eye"></i>流程图</a> ');

          return actions.join('');
        }
      }]
  };
  $.table.init(options);
});
function useLayDateMultiple(cls) {
	layui.use('laydate', function() {
		var laydate = layui.laydate;
		lay('#' + cls).each(function() {
			laydate.render({
				elem: this,
				//theme: 'molv',
				type: 'datetime',
				trigger: 'click'
			});
		});
	});
}



function flowImage(instanceId,defId,taskId){
  var url = '/bpm/instance/instanceImageDialog?instanceId=' + (instanceId?instanceId:'') + '&defId=' + (defId?defId:'') + '&taskId=' + (taskId?taskId:'')
  $.modal.openFullBpm('流程图', url)
}


function typeDict(item){
  var dict = {
    'NORMAL': {text:'普通',color:'label-default'},
    'SIGN': {text:'会签',color:'label-info'},
    'SIGN_SOURCE': {text:'会签_父',color:'label-info'},
    'TRANSFORMING': {text:'事项',color:'label-warning'},
    'TURN': {text:'转办',color:'label-info'},
    'DELIVERTO': {text:'转办',color:'label-warning'},
    'AGENCY': {text:'代理',color:'label-info'},
    'ADD_DO': {text:'加办',color:'label-info'},
    'ADD_SIGN': {text:'加签',color:'label-info'},
  }
  return '<span class="label '+(dict[item] ? dict[item].color : '')+' list-label">'+(dict[item] ? dict[item].text : item)+'</span>'
}

function statusDict(item){
  var dict = {
    'NORMAL': {text:'普通',color:'label-default'},
    'SUSPEND': {text:'挂起',color:'label-info'},
    'LOCK': {text:'锁定',color:'label-warning'},
    'BACK': {text:'驳回',color:'label-warning'},
    'DESIGNATE': {text:'指派',color:'label-info'},
    'TURN': {text:'转办',color:'label-info'},
    'ADDDOED': {text:'加办结束',color:'label-info'},
    'AGENCY': {text:'代理',color:'label-info'},
  }
  return '<span class="label '+(dict[item] ? dict[item].color : '')+' list-label">'+(dict[item] ? dict[item].text : item)+'</span>'
}

function custFormat( value ){
  if(!value)return '';

  if(value < 51 ){
    return '<span class="label label-default list-label">普通</span>';
  }
  if(value == 51 ){
    return '<span class="label label-primary list-label">优先</span>';
  }
  if(value == 52 ){
    return '<span class="label label-success list-label">加急</span>';
  }
  if(value == 53 ){
    return '<span class="label label-info list-label">紧急</span>';
  }
  if(value == 54 ){
    return '<span class="label label-warning list-label">特急</span>';
  }
  if(value >= 55 ){
    return '<span class="label label-danger list-label">火急</span>';
  }
}